package com.soc.web.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.soc.web.client.Gallery.Layout;
import com.soc.web.client.api.Options;
import com.soc.web.client.api.Options.Easing;
import com.soc.web.client.api.Options.TitlePosition;
import com.soc.web.client.api.Options.Transition;
import com.soc.web.client.resources.FancyBoxResources;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Fancybox implements EntryPoint {
	Image image;
	Image image1;
	public void onModuleLoad() {
		
		//FANCYBOX OPTIONS
		Options opts = new Options();
		opts.addTitlePosition(TitlePosition.over);
		opts.addEasingIn(Easing.easeOutBack);
		opts.addEasingOut(Easing.easeInBack);
//		
//		opts.onComplete(new CompleteHandler() {
//			
//			@Override
//			public void onComplete() {
//				Window.alert("Complete");
//			}
//		});
//		opts.onCancel(new CancelHandler() {
//			
//			@Override
//			public void onCancel() {
//				Window.alert("Cancelled");
//			}
//		});
//		opts.onCleanup(new CleanupHandler() {
//			
//			@Override
//			public void onCleanup() {
//				Window.alert("Cleaning UP");
//			}
//		});
//		opts.onStart(new StartHandler() {
//			
//			@Override
//			public void onStart() {
//				Window.alert("Starting");
//			}
//		});
		
//		
//		opts.addTitleFormat(new TitleFormatHandler() {
//			private JSONArray callbackArray;
//			private int index;
//			@Override
//			public String call(String title, JavaScriptObject currentArray,
//					int currentIndex, JavaScriptObject currentOpts) {
//				callbackArray= new JSONArray(currentArray);
//				index = FancyboxUtils.getArrayLengthFromJavascriptObject(callbackArray);
//				if(index != -1) {
//					return "<span id=\"fancybox-title-over\">Image" +  (currentIndex + 1) + " / " + index + " " + title + "</span>";
//				} else {
//					return "<span id=\"fancybox-title-over\">" + title + "</span>";
//				}
//			}
//		});
		
		opts.addTransitionIn(Transition.elastic);
		opts.addTransitionOut(Transition.elastic);
		
		
		
		// GENERAL MEDIA
		Media media = new Media();
		media.setHref("http://www.adobe.com/jp/events/cs3_web_edition_tour/swfs/perform.swf");
		media.setDisplayText("<b>General Media Test</b>");
		media.setTitle("SWF test");		
		media.setOptions(opts);
		media.setThumbnail(new com.google.gwt.user.client.ui.Image(FancyBoxResources.Instance.sunglasses_small()));
		
		// IFRAME
		IFrame frame = new IFrame();
		frame.setFrameHref("http://www.google.com");
		frame.setDisplayText("IFrame Test");
		frame.setOptions(opts);
		frame.setTitle("IFrame Example");
		// AJAX URI REQUEST
		Ajax ajax = new Ajax();
		ajax.setHref(GWT.getModuleBaseURL() + "/ajax1.txt");
		ajax.setDisplayText("Ajax Test");
		ajax.setTitle("Ajax test");		
		ajax.setOptions(opts);
		
		// IMAGE
		image = new Image();
		image.setHref(FancyBoxResources.Instance.sunglasses().getURL());
		image.setThumbnail(new com.google.gwt.user.client.ui.Image(FancyBoxResources.Instance.buildingManagement()));
		image.setOptions(opts);
		image.setTitle("Sunglasses");
		
		// IMAGE
		image1 = new Image();
		image1.setHref(FancyBoxResources.Instance.sunglasses().getURL());
		image1.setThumbnail(new com.google.gwt.user.client.ui.Image(FancyBoxResources.Instance.addressbook()));
		image1.setOptions(opts);
		image1.setTitle("Chandelier");
		
		
		// GALLERY
		
		Gallery<Media> gallery = new Gallery<Media>(Layout.HORIZONTAL, image, image1);
		gallery.setGalleryClass("gallery");
		gallery.setOptions(opts);
		
		// Inline
		HorizontalPanel testPane = new HorizontalPanel();
		testPane.add(new Label("Inline div"));
		testPane.setWidth("200px");
		testPane.setHeight("200px");
		Inline inline = new Inline(testPane);
		inline.setOptions(opts);
		inline.setThumbnail(image1.getThumbnail());
		inline.setDisplayText("Test");
		inline.setTitle("Inline Div Example");
		
		VerticalPanel panel = new VerticalPanel();
		panel.add(image);
		panel.add(media);
		panel.add(frame);
		panel.add(ajax);
		panel.add(inline);
		panel.add(gallery);
		
		RootLayoutPanel.get().add(panel);
	}
}
